/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite.
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.expression;


import dex.compiler.model.base.Place;


/**
 * A mathematical expression using an infix operator, such as <code>x + y</code>.
 */
public class InfixExpression extends Expression {
	
	
	/**
	 * The operator to use. 
	 */
	private Infix operator;
	
	
	/**
	 * The left-hand or first operand.
	 */
	private Expression left;
	
	
	/**
	 * The right-hand or second operand.
	 */
	private Expression right;

	
	/**
	 * Constructs a new operator expression.
	 * 
	 * @param place      the place where the expression originated
	 * @param operator   the operator 
	 * @param left       the left operand
	 * @param right      the right operand
	 */
	public InfixExpression(Place place, Infix operator, Expression left, Expression right) {
		super(place);
		if (operator == null) {
			throw new IllegalArgumentException();
		}
		if (left == null) {
			throw new IllegalArgumentException();
		}
		if (right == null) {
			throw new IllegalArgumentException();
		}
		this.operator = operator;
		this.left = left;
		this.right = right;
	}
	
	

	@Override
	public String toString() {
		return "(" + left + ") " + operator.getSymbol() + " (" + right + ")";
	}


	/**
	 * Returns the left-hand or first operand of the expression.
	 * 
	 * @return  the left operand
	 */
	public Expression getLeft() {
		return left;
	}
	
	
	/**
	 * Returns the right-hand or second operand of the expression.
	 * 
	 * @return the right operand
	 */
	public Expression getRight() {
		return right;
	}
	
	
	/**
	 * Returns the operator.
	 * 
	 * @return  the operator
	 */
	public Infix getOperator() {
		return operator;
	}


}
